import renderHelper from "../compiler/renderHelper.js"
import initComputed from "./init/initComputed/index.js"
import initData from "./init/initData/index.js"
import mount from "../compiler/index.js"
import patch from "../compiler/patch.js"

export default function Vue(options) {
    this.$options = options
    if (!options.data) {
        console.error("please select your data!!!")
        return
    }
    this.$data = options.data
    if (options.methods) {
        this.$methods = options.methods
    }
    if (options.computed) {
        this.$computed = options.computed
    }
    if (options.watch) {
        this.$watch = options.watch
    }
    this._init();
}

Vue.prototype._init = function () {
    initData(this)
    renderHelper(this) // render helper 初始化渲染工具 _c, _v ... 将初始化vnode工具函数挂载到vue实例身上
    this.__patch__ = patch
    initComputed(this)
    if (this.$options.el) {
        this.$mount()
    }
}

Vue.prototype.$mount = function () {
    mount(this)
}
